package com.tms.addressmanagement.controller;

import java.util.Date;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.tms.addressmanagement.domain.Addressmanagement;
import com.tms.addressmanagement.service.IAddressmanagementService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 地址管理Controller
 *
 * @author ruoyi
 * @date 2024-10-29
 */
@RestController
@RequestMapping("/addressmanagement")
public class AddressmanagementController extends BaseController
{
    @Autowired
    private IAddressmanagementService addressmanagementService;




    /**
     * 查询地址管理列表
     */
    @RequiresPermissions("addressmanagement:addressmanagement:list")
    @GetMapping("/list")
    public TableDataInfo list(Addressmanagement addressmanagement)
    {
        startPage();
        List<Addressmanagement> list = addressmanagementService.selectAddressmanagementList(addressmanagement);
        return getDataTable(list);
    }

    /**
     * 导出地址管理列表
     */
    @RequiresPermissions("addressmanagement:addressmanagement:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Addressmanagement addressmanagement)
    {
        List<Addressmanagement> list = addressmanagementService.selectAddressmanagementList(addressmanagement);
        ExcelUtil<Addressmanagement> util = new ExcelUtil<Addressmanagement>(Addressmanagement.class);
        util.exportExcel(response, list, "地址管理数据");
    }

    /**
     * 获取地址管理详细信息
     */
    @RequiresPermissions("addressmanagement:addressmanagement:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(addressmanagementService.selectAddressmanagementById(id));
    }

    /**
     * 新增地址管理
     */
    @RequiresPermissions("addressmanagement:addressmanagement:add")
    @PostMapping
    public AjaxResult add(@RequestBody Addressmanagement addressmanagement)
    {
        addressmanagement.setTime(new Date());
        return toAjax(addressmanagementService.insertAddressmanagement(addressmanagement));
    }

    /**
     * 修改地址管理
     */
    @RequiresPermissions("addressmanagement:addressmanagement:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody Addressmanagement addressmanagement)
    {
        return toAjax(addressmanagementService.updateAddressmanagement(addressmanagement));
    }

    /**
     * 删除地址管理
     */
    @RequiresPermissions("addressmanagement:addressmanagement:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(addressmanagementService.deleteAddressmanagementByIds(ids));
    }
}
